package cn.yi.springboot.druid.service.impl;

import cn.yi.springboot.druid.BaseCurdService;
import cn.yi.springboot.druid.dto.UserDTO;
import cn.yi.springboot.druid.mapper.UserMapper;
import cn.yi.springboot.druid.service.UserService;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

/**
 * @author: yiz
 * @date: 2018/8/1 16:36
 **/
@Service
public class UserServiceImpl extends BaseCurdService<UserDTO> implements UserService {
    @Autowired
    private UserMapper userMapper;

    @Override
    public PageInfo<UserDTO> findByPage(Page page) {
        return super.findbyPage(page, () -> userMapper.selectAllUser());
    }

    @Override
    public void updateUser(UserDTO userDTO) {
        userMapper.updateByPrimaryKey(userDTO);
    }

    @Transactional
    @Override
    public void insertUser(UserDTO userDTO)  {
        userMapper.insert(userDTO);
    }
}
